package com.zhoug.commonlib2.notifycation;

import android.app.Application;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;

import com.zhoug.common2.utils.SystemServiceUtils;
import com.zhoug.commonlib2.App;
import com.zhoug.commonlib2.Params;
import com.zhoug.commonlib2.R;

import androidx.core.app.NotificationCompat;

/**
 * @Author: zhoug
 * @Date: 2024-11-16
 * @Description:
 */
public class WarningNotificationHelper {


    public Notification createNotification(){
        String channelId="001";
        Application application = App.getApplication();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel notificationChannel = new NotificationChannel(channelId, "告警通知", NotificationManager.IMPORTANCE_HIGH);
            notificationChannel.enableLights(true);
            notificationChannel.enableVibration(true);//震动
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            notificationChannel.setSound(soundUri, Notification.AUDIO_ATTRIBUTES_DEFAULT);
            SystemServiceUtils.getNotificationManager(application).createNotificationChannel(notificationChannel);
        }
        Intent intent=new Intent(application,NotificationActivity.class);
        intent.putExtra(Params.CONTENT, "2024-11-16非法入侵");
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        PendingIntent pendingIntent = PendingIntent.getActivity(application, 101, intent, PendingIntent.FLAG_UPDATE_CURRENT, null);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(application, channelId);
        Notification notification = builder.setTicker("报警")
                .setContentTitle("非法入侵报警")
                .setContentText("你有一条非法入侵报警,请及时处理")
                .setSmallIcon(R.drawable.ic_notifycation_warning)
                .setLargeIcon(BitmapFactory.decodeResource(application.getResources(), R.drawable.ic_notifycation_large))
                .setAutoCancel(false)
                .setNumber(12)
                .setCategory(NotificationCompat.CATEGORY_ALARM)
                .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
                .setContentIntent(pendingIntent)
                .build();
        return notification;
    }


}
